app.controller('muying',function($scope,$http,$stateParams,$ionicLoading){
		var obj={}
		obj.title="全部"
		obj.id="kNylmZ"
		$ionicLoading.show()
	$http.get('/api/v2/categories/'+$stateParams.id+'/sub').then(function(res){
		if(res){
			$ionicLoading.hide()
		}
		$scope.muying = res.data
		$scope.muying.unshift(obj)
		$scope.srefs=function($index){
			console.log($index)
			if($index == undefined){
			$http.get('/api/v2/products',{
		params:{
			"category_id":$scope.muying[0].id,
			"offset":0,
			"limit":20,
			"page":1
		}
	}).then(function(res){
		console.log(res)
		$scope.brands=res.data
		$scope.shows()
		$scope.loadMore=function(){
			$scope.shows()
		}
		$scope.loads=function(){
			$scope.loadMore()
		}
	}).catch(function(err){
		$ionicLoading.show({
			duration:3000,
			template:'获取失败'
		})
	})
	$scope.greens=function(){
		$('.run').eq(0).addClass('scrs')
    }
	}else{
	$scope.greens=function(){
		$('.run').eq(0).addClass('')
	}
		$http.get('/api/v2/products',{
		params:{
			"category_id":$scope.muying[$index].id,
			"offset":0,
			"limit":20,
			"page":1
		}
	}).then(function(res){
		console.log(res)
		$scope.brands=res.data
	}).catch(function(err){
		$ionicLoading.show({
			duration:3000,
			template:'获取失败'
		})
	})
		$('.run').eq($index).addClass('scrs').siblings().removeClass('scrs')
	}
	}
		$scope.srefs()
	
})
	$scope.widths=function(){
		var Width = document.querySelectorAll('.run')
		if(Width[0]){
			var Width1 = Width[0].offsetWidth*Width.length
		}
		console.log(Width1)
		return Width1 = Width1 + 'px'
	}
	$scope.shows=function(){
		$http.get('/api/v2/products',{
		params:{
			"category_id":$scope.muying[0].id,
			"offset":$scope.brands.length,
			"limit":20,
			"page":1
		}
	}).then(function(res){
		console.log(res)
		$scope.brands=$scope.brands.concat(res.data)
	})
	}
})